#include <REGX52.H>


int cot   = 0;
int angle = 0;
sbit sg90 = P1^0;

void InitTime0(void)		//0.5毫秒@11.0592MHz
{
	TMOD = 0x01;
	TL0  = 0x33;		//设置定时初值
	TH0  = 0xFE;		//设置定时初值
	TF0  = 0;		//清除TF0标志
	TR0  = 1;		//定时器0开始计时

	//启动中断
	EA  = 1;
	ET0 = 1;
	
}

void Delayms(int ms)		//@11.0592MHz
{
	unsigned char i, j;

	while(ms){
		i = 2;
		j = 199;
		do
		{
		while (--j);
		} while (--i);
		ms --;
	}
}



int main(){
	
	Delayms(300);
	angle = 1;
	cot   = 0;
	sg90  = 1;
	InitTime0();
	while(1){
		cot = 0;
		angle = 1;
		Delayms(2000);
		cot = 0;
		angle = 4;
		Delayms(2000);
	}
	
}


void T0Handler() interrupt 1{
	
	cot++;
	TL0 = 0x33;
	TH0 = 0xFE;	
	

	if(cot < angle){
		sg90 = 1;
	}else{
		sg90 = 0;
	}
	
	if(cot == 40){
	
		cot  = 0;
		sg90 = 1;
	}
}